package com.example.mapper;

import com.example.entity.City;
import com.example.entity.Help;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 操作help相关数据接口
*/
public interface HelpMapper {
    void insert(Help help);
    //关联查询
    @Select("select help.*, city.name as cityName, volunteer.name as volunteerName " +
            "from help " +
            "left join city on help.city_id = city.id " +
            "left join volunteer on help.volunteer_id = volunteer.id")
    List<Help> selectAll();

    @Select("select help.*, city.name as cityName, volunteer.name as volunteerName " +
            "from help " +
            "left join city on help.city_id = city.id " +
            "left join volunteer on help.volunteer_id = volunteer.id " +
            "where help.name like concat('%', #{name}, '%')")
    List<Help> selectByName(String name);

    void updateById(Help help);

    @Delete("delete from help where id = #{id}")
    void deleteById(Integer id);


    @Select("select help.*, city.name as cityName, volunteer.name as volunteerName " +
            "from help " +
            "left join city on help.city_id = city.id " +
            "left join volunteer on help.volunteer_id = volunteer.id " +
            "where help.name like concat('%', #{name}, '%')and volunteer_id = #{volunteerId}")
    List<Help> selectByNameAndVolunteerId(@Param("name") String name, @Param("teacherId") Integer teacherId);

    @Select("select help.*, city.name as cityName, volunteer.name as volunteerName " +
            "from help " +
            "left join city on help.city_id = city.id " +
            "left join volunteer on help.volunteer_id = volunteer.id " +
            "where  volunteer_id = #{volunteerId}")
    List<Help> selectAllByVolunteerId(Integer volunteerId);

    @Select("select * from help where id= #{id}")
    Help selectById(Integer helpId);
}